package intelligentcity.model.intersection;

import java.util.ArrayList;
import java.util.List;

import intelligentcity.model.Point;
import intelligentcity.model.Road;
import intelligentcity.model.streets.HorizontalStreet;
import intelligentcity.model.streets.Street;
import intelligentcity.model.streets.VerticalStreet;

public class Intersection extends Road {

    private final VerticalStreet verticalStreet;
    private final HorizontalStreet horizontalStreet;    
    private final List<Point> pointsOfTurn;

    public Intersection(VerticalStreet verticalStreet, HorizontalStreet horizontalStreet) {
        
        this.verticalStreet = verticalStreet;
        this.horizontalStreet = horizontalStreet;
        this.pointsOfTurn = new ArrayList<>(4);
        
        int x1 = verticalStreet.getFirstStreet().getP1().getX();
        int x2 = verticalStreet.getSecondStreet().getP1().getX();
        int y1 = horizontalStreet.getFirstStreet().getP1().getY();
        int y2 = horizontalStreet.getSecondStreet().getP1().getY();
        
        pointsOfTurn.add(new Point(x1, y1));
        pointsOfTurn.add(new Point(x2, y1));
        pointsOfTurn.add(new Point(x1, y2));
        pointsOfTurn.add(new Point(x2, y2));
    }

    public VerticalStreet getVerticalStreet() {
        return verticalStreet;
    }

    public HorizontalStreet getHorizontalStreet() {
        return horizontalStreet;
    }
    
    public List<Point> getPointsOfTurn() {
        return pointsOfTurn;
    }
  
    @Override
    public String toString() {
        return verticalStreet.toString() + " x " + horizontalStreet.toString();
    }
    
    @Override
    public boolean equals(Object o) {
        if (o instanceof Intersection && ((Intersection) o).getHorizontalStreet().equals(horizontalStreet)
                && ((Intersection) o).getVerticalStreet().equals(verticalStreet)) {
            return true;
        }
        return false;
    }

}
